class Solution {
public:
    int circleGame(vector<vector<int>>& toys, vector<vector<int>>& circles, int r) {
        int n = toys.size();
        int m = circles.size();
        unordered_map<unsigned long long,int> myMap;
        for(int i = 0;i < n;i++){
            vector<int> toy = toys[i];
            if(toy[2] > r)continue;
            unsigned long long pos = ((unsigned long long)toy[0] << 30) + (unsigned long long)toy[1];
            myMap[pos] = i;
        }
        int cnt = 0;

        for(vector<int> circle : circles){
            for(int i = -10;i <= 10;i++){
                for(int j = -10;j <= 10;j++){
                    int newX = circle[0] + i;
                    int newY = circle[1] + j;
                    unsigned long long pos = ((unsigned long long)newX  << 30) + (unsigned long long)newY;
                    auto it = myMap.find(pos);
                    if(it != myMap.end()){
                        int p = it->second;
                        if((toys[p][0] - circle[0]) * (toys[p][0] - circle[0]) + (toys[p][1] - circle[1]) * (toys[p][1] - circle[1]) <= (r - toys[p][2]) * (r - toys[p][2])) {
                            cnt++;
                            myMap.erase(it);
                        }
                    }
                }
            }
        }
    return cnt;
    }
};
